//
//  MainTabBar.swift
//  WeiBo001
//
//  Created by Zhanghong on 15/6/26.
//  Copyright © 2015年 HeiMa. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    var childBtnCount = 5
    override func layoutSubviews() {
        super.layoutSubviews()
//        print(self.subviews as NSArray)
        let w = bounds.width / CGFloat(childBtnCount)
        let h = bounds.height
        let rect = CGRectMake(0, 0, w, h)
//        print(composeButton)
        composeButton.frame = CGRectOffset(rect, 2*w, 0)
        
        var index = 0
        for v in subviews {
            if v is UIControl && !(v is UIButton){
            v.frame = CGRectOffset(rect, CGFloat(index) * w, 0)
                index += index == 1 ? 2 : 1
            }
        }
    }
    
    lazy var composeButton : UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Normal)
        self.addSubview(btn)
        return btn
    }()
}
